package com.netease.financial.ui.fragment;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.view.View;

import com.netease.financial.NfsApplication;
import com.netease.financial.internal.di.HasComponent;
import com.netease.financial.navigation.Navigator;
import com.tendcloud.tenddata.TCAgent;

/**
 * Created by wyf on 6/10/15.
 */
public abstract class BaseFragment extends Fragment {

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (hidden) {
            TCAgent.onPageEnd(getActivity(), getClass().getSimpleName());
        } else {
            TCAgent.onPageStart(getActivity(), getClass().getSimpleName());
        }
    }

    public boolean performCustomViewItemSelected(View view) {
        if (isVisible()) {
            if (onCustomViewItemSelected(view)) {
                return true;
            }
        }
        return false;
    }

    public boolean onCustomViewItemSelected(View view) {
        return false;
    }

    public void onNewIntent(Intent intent) {
    }

    /**
     * Gets a component for dependency injection by its type.
     */
    @SuppressWarnings("unchecked")
    protected <C> C getComponent(Class<C> componentType) {
        return componentType.cast(((HasComponent<C>) getActivity()).getComponent());
    }

    protected Navigator getNavigator() {
        return NfsApplication.getApplication().getNavigator();
    }

}
